package com.comando.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.comando.dao.UserDao;
import com.comando.dto.UserDto;
import com.comando.model.UserT;
import com.comando.service.LoginService;

@Service(value="loginService")
public class LoginServiceImpl implements LoginService {

	private UserDao userDao;
	
	public UserDao getUserDao() {
		return userDao;
	}
	
	@Autowired
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	@Override
	public UserDto login(UserDto userDto) {
		//Encrypt.e(user.getCpwd())
		UserT t = userDao.get("from UserT t where t.loginName = ? or t.email = ? and t.password = ?", 
				new Object[] { userDto.getLoginName(), userDto.getEmail(), userDto.getPassword() });
		if (t != null) {
			BeanUtils.copyProperties(t, userDto, new String[] { "password" });
			return userDto;
		}
		return null;
	}

}
